# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Alexandre Filgueira <alexfilgueira@antergos.com>

pkgbase=nemo-extensions
pkgname=(nemo-audio-tab
         nemo-emblems
         nemo-fileroller
         nemo-image-converter
         nemo-pastebin
         nemo-preview
         nemo-python
         nemo-seahorse
         nemo-share
         nemo-terminal)
        #nemo-compare
        #nemo-dropbox dropbox in AUR
        #nemo-media-columns pypdf2 in AUR but mostly unmaintained
        #nemo-repairer
pkgver=5.6.0
pkgrel=3
pkgdesc="Various extensions for Nemo"
arch=(loong64 x86_64)
license=(GPL2)
url="https://github.com/linuxmint/nemo-extensions"
depends=(nemo)
_preview_deps=(cjs clutter-gtk clutter-gst libmusicbrainz5 gtksourceview4 xreader)
_python_deps=(python-gobject python-setuptools)
_seahorse_deps=(libcryptui)
makedepends=(intltool gobject-introspection meson samurai)
makedepends+=("${_preview_deps[@]}" "${_python_deps[@]}" "${_seahorse_deps[@]}")
options=(!emptydirs)
source=("${url}/archive/${pkgver}/${pkgbase}-${pkgver}.tar.gz"
        "$pkgbase-simplify_gpgme_lookup.patch::https://github.com/linuxmint/nemo-extensions/commit/601374dab4506c0e791cfbd1ecf5e9f1451c1660.patch")
sha256sums=('6c334b320541672b1c6ac8ec2ffade5a0eb413549fa680ccce56914055f537f0'
            '0abe0e913558d3cebd3fd189628960a79af25cc9cd70faa238db2dca6d061711')
b2sums=('49dd9683aeae036c042f791ff52d3bf12226034e07972ac150ffcfba34543a60b3776db6426429a37d404aa11c828b42b1fc28c5ba0180fce65674960d14bd4c'
        '29f31f5d5b0c925a86c386bcc559d420ca24ab69a1a9d8d82265153617689e319d2b70e07a5c6205d76546ec5f05aa545ae40b6a79823559aef3afff885b25e8')

prepare() {
  cd $pkgbase-$pkgver
  patch --forward --strip=1 --input=../$pkgbase-simplify_gpgme_lookup.patch
  rm -r ./*/debian # Fix build with newer setuptools
}

build() {
  cd ${pkgbase}-${pkgver}

  for _dir in "${pkgname[@]}"; do
    if [[ -f ${_dir}/meson.build ]]; then
      mkdir -p ${_dir}/build
      pushd ${_dir}/build
      arch-meson --libexecdir=lib/${_dir} ..
      samu
      popd
    fi
  done

  cd nemo-audio-tab
  python setup.py build
  cd ..

  cd nemo-emblems
  python setup.py build
  cd ..

  cd nemo-pastebin
  python setup.py build
  cd ..
}

package_nemo-audio-tab(){
  pkgdesc="View audio tag information in Nemo properties tab"
  depends+=(nemo-python python-mutagen)
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}
  python setup.py install --prefix=/usr --root="${pkgdir}" --skip-build --optimize=1
}

package_nemo-emblems(){
  pkgdesc="Change a folder or file emblem in Nemo"
  depends+=(nemo-python)
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}
  python setup.py install --prefix=/usr --root="${pkgdir}" --skip-build --optimize=1
}

package_nemo-fileroller(){
  pkgdesc="File archiver extension for Nemo"
  depends+=(file-roller)
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}/build
  DESTDIR="${pkgdir}" samu install
}

package_nemo-image-converter(){
  pkgdesc="Nemo extension to rotate/resize image files"
  depends+=(imagemagick)
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}/build
  DESTDIR="${pkgdir}" samu install
}

package_nemo-preview(){
  pkgdesc="Quick file previewer for Nemo"
  depends+=("${_preview_deps[@]}")
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}/build
  DESTDIR="${pkgdir}" samu install
}

package_nemo-pastebin(){
  pkgdesc="Nemo extension to send files to a pastebin"
  depends+=(nemo-python pastebinit)
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}
  python setup.py install --prefix=/usr --root="${pkgdir}" --skip-build --optimize=1
}

package_nemo-python() {
  pkgdesc="Python3 binding for Nemo components"
  depends+=("${_python_deps[@]}")

  cd ${pkgbase}-${pkgver}/${pkgname}/build
  DESTDIR="${pkgdir}" samu install
}

package_nemo-seahorse(){
  pkgdesc="PGP encryption and signing extension for Nemo"
  depends+=("${_seahorse_deps[@]}")
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}/build
  DESTDIR="${pkgdir}" samu install
}

package_nemo-share(){
  pkgdesc="Samba extension for Nemo"
  depends+=(samba)
  optdepends=('cinnamon-translations: i18n')

  cd ${pkgbase}-${pkgver}/${pkgname}/build
  DESTDIR="${pkgdir}" samu install
}

package_nemo-terminal(){
  pkgdesc="Embedded terminal window for Nemo"
  depends=(nemo-python vte3)

  cd ${pkgbase}-${pkgver}/${pkgname}
  install -Dm644 src/nemo_terminal.py -t "${pkgdir}"/usr/share/nemo-python/extensions/
  install -Dm755 src/nemo-terminal-prefs.py "${pkgdir}"/usr/bin/nemo-terminal-prefs
  install -Dm644 src/org.nemo.extensions.nemo-terminal.gschema.xml -t "${pkgdir}"/usr/share/glib-2.0/schemas/
  install -Dm644 pixmap/logo_120x120.png -t "${pkgdir}"/usr/share/nemo-terminal/
}

## missing kaa-base in the repos
#package_nemo-media-columns(){
#    pkgdesc=("A Nemo extension to display music/EXIF and PDF metadata info in the Nemo List View")
#    depends=('nemo-python' 'mutagen' 'python2-exiv2' 'python2-kaa-base' 'python2-pillow' 'python2-pypdf')
#
#    cd "${srcdir}"/${pkgbase}-${pkgver}/${pkgname}
#    install -Dm644 nemo-media-columns.py \
#        "${pkgdir}"/usr/share/nemo-python/extensions/nemo-media-columns.py
#}

## no clue what any of this does
# package_nemo-compare() {
#   cd ${pkgbase}-${pkgver}/nemo-compare

#   pkgdesc="Context menu comparison extension for Nemo file manager"
#   depends=(python2 python2-xdg meld nemo-python)

#   install -d ${pkgdir}/usr/share/applications/
#   install -d ${pkgdir}/usr/share/nemo-compare/

#   install -Dm755 ${srcdir}/data/nemo-compare-preferences.desktop \
#                   /usr/share/applications/nemo-compare-preferences.desktop
#   install -Dm755 ${srcdir}/data/nemo-compare-notification \
#                   /usr/share/nemo-compare/nemo-compare-notification
#   install -Dm755 ${srcdir}/src/nemo-compare.py \
#                   /usr/share/nemo-compare/nemo-compare.py
#   install -Dm755 ${srcdir}/src/utils.py \
#                   /usr/share/nemo-compare/utils.py
#   install -Dm755 ${srcdir}/src/nemo-compare-preferences.py \
#                   /usr/share/nemo-compare/nemo-compare-preferences.py

# }
